public class Complex{
    double RealPart;
    double ImagePart;
    public double getRealPart(){
        return RealPart;
    }
    public double getImagePart(){
        return ImagePart;
    }

    public Complex(){}
    public Complex(double R,double I){
        RealPart = R;
        ImagePart = I;
    }

    public boolean equals(Object obj){
        if(this == obj){
            return true;
        }
        if(!(obj instanceof Complex)) {
            return false;
        }
        Complex complex = (Complex) obj;
        if(complex.RealPart != ((Complex) obj).RealPart) {
            return false;
        }
        if(complex.ImagePart != ((Complex) obj).ImagePart) {
            return false;
        }
        return true;
    }
    public String toString(){
        String s = new String();
        if(ImagePart>0)
            s = getRealPart()+"+"+getImagePart()+"i";
        if(ImagePart==0)
            s = getRealPart()+"";
        if(ImagePart<0)
            s = getImagePart()+getImagePart()+"i";
        if(RealPart==0)
            s = getImagePart()+"i";
        if(ImagePart==0&&RealPart==0)
            s = "0";
        return s;
    }

    public Complex ComplexAdd(Complex a){
        return new Complex(RealPart+a.RealPart,ImagePart+a.ImagePart);
    }
    public Complex ComplexSub(Complex a){
        return new Complex(RealPart-a.RealPart,ImagePart-a.ImagePart);
    }
    public Complex ComplexMulti(Complex a){
        return new Complex(RealPart*a.RealPart,ImagePart*a.ImagePart);
    }
    public Complex ComplexDiv(Complex a){
        return new Complex((RealPart * a.ImagePart + ImagePart * a.RealPart) / (a.ImagePart * a.ImagePart + a.RealPart * a.RealPart), (ImagePart * a.ImagePart + RealPart * a.RealPart) / (a.RealPart * a.RealPart + a.RealPart * a.RealPart));
    }

}